extends ./layout

block contentAll
  .main

    .user
      .login-logo 
        h2 用户注册
      //- span
      //-   i.fa.fa-user-circle-o.fa-3x.login-fa
      .login
        .inset
          // ---start-main--
          form(action='', method='post', onsubmit="return false;")
            div.form-item
              span
                label(for='username' ) 用 户 名
              span
                input#username.textbox(type='text',required='true')
            div.form-item
              span
                label(for='#password') 用户密码
              span
                input#password.password(type='password',required='true')
            div.form-item
              span
                label(for='#passwordA') 确认密码
              span
                input#passwordA.password(type='password',required='true')
            div.form-item
              span
                label(for='email' ) 邮 &nbsp;&nbsp;&nbsp;箱
              span
                input#email.textbox(type='email',required='true')      
            .sign
              .submit
                input(type='submit', onclick='submitRegister()', value='马上注册')
              .submit
                input(type='reset',  value='重置')
              script(type="text/javascript").
                function submitRegister(){
                  var username = $("#username").val();
                  var password = $("#password").val();
                  var passwordA = $("#passwordA").val();
                  var email = $("#email").val();
                  console.log(password,passwordA);
                  if(password !== passwordA){
                    Swal({
                      text: '两次密码不一致，请重新输入！',
                      type: 'error',
                      confirmButtonText: "OK",
                    }).then(function(isConfirm){
                      if(isConfirm === true){
                        return 0;
                      }
                    });
                    return 0;
                  }
                  $.ajax({
                    url:'/user/register',
                    data:{
                      "username":username,
                      "password":password,
                      "email":email,
                    },
                    type:'POST',
                    success:function(msg){
                      if(!msg.status){
                        Swal({
                          title: msg.text,
                          type: 'error',
                          confirmButtonText: "OK",
                        }).then(function(isConfirm){
                          if(isConfirm === true){
                            return 0;
                          }
                        });
                      }else{
                        Swal({
                          title: msg.text,
                          type: 'success',
                          confirmButtonText: "OK",
                        }).then(function(isConfirm){
                          if(isConfirm.value == true){
                            window.location.href='/';
                          }
                        });
                      }
                    }
                  });
                }    
              span.forget-pass
                a(href='#') 联系我们！
              .clear  
      // ---//end-main--

